<template>
  <div class="area-detail" v-title :data-title="$t('router.areaNationalTitle')">
    <div class="Breadcrumbback">
      <Breadcrumb></Breadcrumb>
    </div>
    <el-radio-group
      v-if="this.$route.params.sort == 'world'"
      v-model="countryId"
      @change="toggle"
    >
      <el-radio v-model="countryId" label="">{{
        $t("main.selectAll")
      }}</el-radio>
      <el-radio
        v-for="item of areas"
        :key="item.countryId"
        :label="item.countryId"
      >
        {{
          $i18n.locale === "zh"
            ? item.displayCname || item.displayName
            : item.displayName
        }}
      </el-radio>
    </el-radio-group>
    <div
      class="list"
      v-infinite-scroll="load"
      infinite-scroll-disabled="isPage"
      infinite-scroll-delay="120"
      infinite-scroll-distance="10"
      infinite-scroll-immediate="false"
    >
      <album-list
        :listData="list"
        :loading="loading"
        v-loading="fullscreenLoading"
      ></album-list>
    </div>
    <nice-empty
      v-show="list.length == 0 && fullscreenLoading == false"
      :emptyText="$t('public.noData')"
    ></nice-empty>
    <div class="page-wrap" v-show="isPage">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-size="params.pageSize"
        background
        hide-on-single-page
        layout="total, prev, pager, next, jumper"
        :total="total"
        :small="isMobile"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import albumList from "@/components/common/albumList/Index";
import Breadcrumb from "@/components/common/Breadcrumb/Index";
export default {
  data() {
    return {
      areas: [], //国家列表
      list: [], //专辑列表
      //数据载入动画
      fullscreenLoading: true,
      // 是否显示加载动画
      loading: false,
      // 请求参数
      params: {
        pageSize: 6, // 返回数量
        pageNum: 1, // 当前页数
      },
      countryId: "", //国家ID
      //是否禁止加载数据或分页
      isPage: false,
      total: 0, //总条数
    };
  },
  components: {
    albumList,
    Breadcrumb,
  },
  computed: {
    isMobile() {
      return this.$store.getters.isMobile;
    },
    isIE() {
      return this.$store.getters.isIE;
    },
  },
  watch: {},
  created() {},
  mounted() {
    if (this.isIE) {
      this.params.pageSize = 14;
    }
    if (this.$route.params.sort == "world") {
      this.getCountryList();
    }
    this.getCountryAlbum();
  },
  methods: {
    //分页 每页条数
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.getCountryAlbum();
    },
    //当前页
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.list = [];
      this.getCountryAlbum();
    },
    toggle(id) {
      this.countryId = id;
      this.list = [];
      this.getCountryAlbum();
    },
    //获取国家
    async getCountryList() {
      try {
        let params = {
          regionId: this.$route.params.id,
        };
        let res = await this.$api.national.getCountryList(params);
        if (res.code === 1000000) {
          this.areas = res.source ? res.source : [];
        }
      } catch (e) {
        console.log(e);
      }
    },
    //获取专辑
    async getCountryAlbum() {
      this.fullscreenLoading = true;
      try {
        let res, params;
        if (this.$route.params.sort == "world") {
          params = Object.assign(
            { regionId: this.$route.params.id },
            this.params,
            { countryId: this.countryId }
          );
          res = await this.$api.national.getCountryAlbum(params);
        } else if (this.$route.params.sort == "en") {
          params = Object.assign(
            { countryId: this.$route.params.id },
            this.params
          );
          res = await this.$api.national.getCountryAlbum(params);
        }
        if (res.code === 1000000) {
          this.list = res.source
            ? this.utils.processingData(this.list, res.source)
            : [];
          this.total = res.total;
          this.fullscreenLoading = false;
          if (res.size < 14 && res.size < res.total) {
            this.loading = true;
            this.isPage = false;
          } else {
            this.loading = false;
            this.isPage = true;
          }
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 加载更多
    load() {
      this.params.pageSize += 4;
      this.getCountryAlbum();
    },
  },
};
</script>

<style lang="scss" scoped>
.area-detail {
  .el-radio-group {
    line-height: 30px;
  }
}
</style>
